package com.cxz.study.infra.repo.order;

import com.cxz.study.domain.order.Order;
import com.cxz.study.domain.order.OrderRepository;
import com.cxz.study.infra.repo.order.entity.OrderDO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @className: OrderRepositoryImpl
 * @author: ocxz1
 * @date: 2025/6/13 下午10:13
 * @Version: 1.0
 * @description: ddd-struct3
 */
@Repository
@RequiredArgsConstructor
public class OrderRepositoryImpl implements OrderRepository {
    private final OrderMyBatisMapper orderMyBatisMapper;
    private final OrderMapperStruct orderMapperStruct;

    @Override
    public void save(Order order) {
        OrderDO orderDO = orderMapperStruct.toOrderDO(order);
        orderMyBatisMapper.save(orderDO);
    }

    @Override
    public Order findById(Long orderId) {
        OrderDO orderDO = orderMyBatisMapper.findById(orderId);
        return orderMapperStruct.toOrder(orderDO);
    }

    @Override
    public void updateStatus(Order order) {
        OrderDO orderDO = orderMapperStruct.toOrderDO(order);
        orderMyBatisMapper.updateStatus(orderDO);
    }
}
